#set path=cmake_path;%PATH%
#cd build/mingw32-debug
#cmake.exe -DCMAKE_BUILD_TYPE=Debug ../../
CMAKE_MINIMUM_REQUIRED(VERSION 2.5)
PROJECT(owl)
#MESSAGE("GUI system is ${GUI}")
#only for visual studio, filter out a subset of build configuration
SET(CMAKE_CONFIGURATION_TYPES Debug,Release,MinSizeRel,RelWithDebInfo)

#apparently CMake does not enfore a particular debug flag (NDEBUG?). Let's do our own.
IF(${CMAKE_BUILD_TYPE} STREQUAL Debug)
  ADD_DEFINITIONS(-DDEBUG)
  #SET(CMAKE_CXX_FLAGS_DEBUG "-DDEBUG "${CMAKE_CXX_FLAGS_DEBUG})
ENDIF (${CMAKE_BUILD_TYPE} STREQUAL Debug)

#To force a build type (usually done via -DCMAKE_BUILD_TYPE=Debug while generating in output directory)
#SET(CMAKE_BUILD_TYPE Debug)

#SET(CMAKE_FILES_DIRECTORY ${CMAKE_GENERATOR})

#to differentiate debug and release
#if(MSVC)
set(CMAKE_DEBUG_POSTFIX "d")
#endif(MSVC)

# Ensure the CMAKE_LIBRARY_OUTPUT_DIRECTORY is set
#IF(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
#  IF(WIN32)
#    SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY "bin")
#  ELSE(WIN32)
#    SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY "lib")
#  ENDIF(WIN32)
#ENDIF(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
#SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})

#SET(ZLIB_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/thirdparty/zlib/zlib-1.2.6 ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/zlib/zlib-1.2.6)
SET(UTILS_INCLUDE_DIR 	${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/libutils)

INCLUDE_DIRECTORIES(
	#C:/Dev/clang/mingw64/lib/clang/3.1/include
		${UTILS_INCLUDE_DIR}
	)
#LINK_DIRECTORIES(${LINK_DIRECTORIES} ${PROJECT_BINARY_DIR}/bin)

#ADD_SUBDIRECTORY(thirdparty/libharu)

#FILE(GLOB_RECURSE pdfqrsplit_SOURCES src/*.cp*)

SET (owl_SOURCES
	src/main.cpp
	#src/index.cpp
	src/utils.cpp
	)
FILE(GLOB_RECURSE owl_HEADERS src/*.h thirdparty/*.h)

SOURCE_GROUP(Files FILES ${owl_SOURCES} ${owl_HEADERS})

#added to compilers
#ADD_DEFINITIONS(-DNO_ICONV)
ADD_DEFINITIONS(-D_MINGW)
#-s is for stripping
ADD_DEFINITIONS(-fno-rtti -fno-exceptions -s)
LINK_DIRECTORIES(${LINK_DIRECTORIES}
	#${PROJECT_BINARY_DIR}/bin
	#thirdparty/xpdf
	#			 thirdparty/zxing
	#			 thirdparty/libharu/libhpdf-2.3.0RC2/src
	#C:/Dev/mingw64/lib/gcc/x86_64-w64-mingw32/4.7.0
)

#ADD_LIBRARY(xpdf STATIC ${xpdf_SOURCES} ${xpdf_HEADERS})
ADD_EXECUTABLE(owl_csearch ${owl_SOURCES} ${owl_HEADERS})
TARGET_LINK_LIBRARIES(owl_csearch ws2_32)
#setting properties for a single target
#--disable-shared --enable-static ?
SET_TARGET_PROPERTIES(owl_csearch PROPERTIES LINK_FLAGS "-static-libgcc -static-libstdc++ --static")
#else, for more general linker options:
#SET (CMAKE_SHARED_LINKER_FLAGS ${CMAKE_SHARED_LINKER_FLAGS_INIT} $ENV{LDFLAGS}
#     CACHE STRING "Flags used by the linker during the creation of dll's.")
# module linker flags
#SET (CMAKE_MODULE_LINKER_FLAGS ${CMAKE_MODULE_LINKER_FLAGS_INIT} $ENV{LDFLAGS}
#     CACHE STRING "Flags used by the linker during the creation of modules.")
#FILE(GLOB_RECURSE owl_WWW www/*.*)
INSTALL (FILES owl_WWW DESTINATION www)
INSTALL (TARGETS owl_csearch DESTINATION bin)
